package com.poetry.vup.user.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.poetry.vup.common.entity.user.VupUserDO;
import com.poetry.vup.user.domain.VupUserVO;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface VupUserMapper extends BaseMapper<VupUserDO> {

    /**
     * 查找所有用户
     * @param offset
     * @param pageSize
     * @return
     */
    @Select("<script>" +
            "select " +
            "t.id," +
            "t.user_name," +
            "t.user_passord," +
            "t.unique_identification," +
            "t.role," +
            "t.gmt_create," +
            "t.gmt_modified from vup_user t "+
            "WHERE 1=1 "+
            "LIMIT #{offset}, #{pageSize}"+
            "</script>")
    @Results({
            @Result(column = "id", property = "id"),
            /*@Result(column = "user_name", property ="userName" ),
            @Result(column = "user_passord", property = "userPassord"),*/
            @Result(column = "unique_identification", property = "uniqueIdentification"),
            @Result(column = "role", property = "role"),
            @Result(column = "gmt_create", property = "gmtCreate"),
            @Result(column = "gmt_modified", property = "gmtModified")
    })
    List<VupUserVO> findAllVupUser(@Param("offset") int offset, @Param("pageSize") int pageSize);

    @Select("<script>" +
            "SELECT count(*) FROM vup_user"+
            "</script>")
    Long getCount();

    /**
     * 登录
     * @param userName
     * @param passWord
     * @return
     */
    @Select("select " +
            "t.id," +
            "t.unique_identification," +
            "t.role," +
            "t.gmt_create," +
            "t.gmt_modified from vup_user t WHERE " +
            "t.user_name = '${userName}' AND t.user_passord = '${passWord}'")
    @Results({
            @Result(column = "id", property = "id"),
            @Result(column = "unique_identification", property = "uniqueIdentification"),
            @Result(column = "role", property = "role"),
            @Result(column = "gmt_create", property = "gmtCreate"),
            @Result(column = "gmt_modified", property = "gmtModified")
    })
    VupUserVO findUserNameAndPassWord(@Param("userName") String userName, @Param("passWord") String passWord);
}
